package cn.com.lsy.product.lepao.controller;

import cn.com.lsy.product.lepao.common.Constant;
import cn.com.lsy.product.lepao.controller.base.BaseController;
import cn.com.lsy.product.lepao.model.entities.LpAdminTbl;
import cn.com.lsy.product.lepao.model.entities.LpMenuTbl;
import cn.com.lsy.product.lepao.model.entities.LpParentMenuTbl;
import cn.com.lsy.product.lepao.model.entities.LpRoleTbl;
import cn.com.lsy.product.lepao.model.mt.entities.AdminUserListDto;
import cn.com.lsy.product.lepao.request.*;
import cn.com.lsy.product.lepao.request.base.PageSearchParam;
import cn.com.lsy.product.lepao.response.*;
import cn.com.lsy.product.lepao.response.base.ApiResponseEnum;
import cn.com.lsy.product.lepao.response.base.BaseRet;
import cn.com.lsy.product.lepao.response.base.PageInfo;
import cn.com.lsy.product.lepao.service.IAdminService;
import cn.com.lsy.product.lepao.service.IRoleService;
import cn.com.lsy.product.lepao.util.CommonFunctionUtil;
import cn.com.lsy.product.lepao.util.DozerMapperUtil;
import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import net.sf.json.JSONArray;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

@Api(value = "角色管理接口", tags = "角色管理接口")
@RestController
@RequestMapping(value = "/lepao/console/doAuth")
public class RoleController extends BaseController {

    private Logger log = Logger.getLogger(RoleController.class);

    @Autowired
    IRoleService iRoleService;
    @Autowired
    IAdminService iAdminService;

    @RequestMapping(value = "/roleList", method = RequestMethod.POST)
    @ApiOperation(notes = "角色列表", httpMethod = "POST", value = "角色列表")
    public BaseRet<List<RoleListRet>> roleList() {

        BaseRet<List<RoleListRet>> ret = new BaseRet<List<RoleListRet>>();

        try {

            List<LpRoleTbl> list = iRoleService.selectRoleList();

            List<RoleListRet> listRet = DozerMapperUtil.mapList(list, RoleListRet.class);

            ret.setMsg("查询成功");
            ret.setCode(ApiResponseEnum.API_RESPONSE_SUCCESS);
            ret.setData(listRet);


        } catch (Exception e) {
            log.error(e.getMessage(), e);
            ret.setCode(ApiResponseEnum.API_RESPONSE_ERROR);
            ret.setMsg(e.getMessage());
        }

        return ret;
    }


    @RequestMapping(value = "/addRole", method = RequestMethod.POST)
    @ApiOperation(notes = "添加角色", httpMethod = "POST", value = "添加角色")
    public BaseRet<String> addRole(@ApiParam(value = "请求参数", required = true) @Valid @RequestBody AddRoleParam param,
                                   BindingResult result) {

        BaseRet<String> ret = new BaseRet<String>();

        try {

            checkParam(result);

            JSONArray obj = JSONArray.fromObject(param.getMenu());

            LpRoleTbl lpRoleTbl = new LpRoleTbl();
            lpRoleTbl.setMenuJson(obj.toString());
            lpRoleTbl.setName(param.getName());
            lpRoleTbl.setInsertTime(CommonFunctionUtil.getDateTime(Constant.formatType.second));
            lpRoleTbl.setUpdateTime(CommonFunctionUtil.getDateTime(Constant.formatType.second));

            if (iRoleService.insertRole(lpRoleTbl)) {

                ret.setCode(ApiResponseEnum.API_RESPONSE_SUCCESS);
                ret.setMsg("添加成功");

            } else {

                ret.setCode(ApiResponseEnum.API_RESPONSE_ERROR);
                ret.setMsg("添加失败");
            }

        } catch (Exception e) {
            log.error(e.getMessage(), e);
            ret.setCode(ApiResponseEnum.API_RESPONSE_ERROR);
            ret.setMsg(e.getMessage());
        }

        return ret;
    }


    @RequestMapping(value = "/roleInfo", method = RequestMethod.POST)
    @ApiOperation(notes = "角色详情", httpMethod = "POST", value = "角色详情")
    public BaseRet<RoleInfoRet> roleInfo(@ApiParam(value = "请求参数", required = true) @Valid @RequestBody ActionLibraryInfoParam param,
                                         BindingResult result) {

        BaseRet<RoleInfoRet> ret = new BaseRet<RoleInfoRet>();

        try {

            checkParam(result);

            LpRoleTbl info = iRoleService.selectRoleInfo(param.getId());
            RoleInfoRet roleInfoRet = new RoleInfoRet();
            roleInfoRet.setId(info.getId());
            roleInfoRet.setName(info.getName());
            if (StringUtils.isNotEmpty(info.getMenuJson())) {
                roleInfoRet.setMenu(JSONObject.parseArray(info.getMenuJson(), Integer.class));
            }

            ret.setMsg("查询成功");
            ret.setCode(ApiResponseEnum.API_RESPONSE_SUCCESS);
            ret.setData(roleInfoRet);


        } catch (Exception e) {
            log.error(e.getMessage(), e);
            ret.setCode(ApiResponseEnum.API_RESPONSE_ERROR);
            ret.setMsg(e.getMessage());
        }

        return ret;
    }


    @RequestMapping(value = "/updateRole", method = RequestMethod.POST)
    @ApiOperation(notes = "修改角色", httpMethod = "POST", value = "修改角色")
    public BaseRet<String> updateRole(@ApiParam(value = "请求参数", required = true) @Valid @RequestBody UpdateRoleParam param,
                                      BindingResult result) {

        BaseRet<String> ret = new BaseRet<String>();

        try {

            checkParam(result);
            JSONArray obj = JSONArray.fromObject(param.getMenu());

            LpRoleTbl lpRoleTbl = new LpRoleTbl();
            lpRoleTbl.setMenuJson(obj.toString());
            lpRoleTbl.setName(param.getName());
            lpRoleTbl.setId(param.getId());
            lpRoleTbl.setUpdateTime(CommonFunctionUtil.getDateTime(Constant.formatType.second));

            if (iRoleService.updateRole(lpRoleTbl)) {

                ret.setCode(ApiResponseEnum.API_RESPONSE_SUCCESS);
                ret.setMsg("修改成功");

            } else {

                ret.setCode(ApiResponseEnum.API_RESPONSE_ERROR);
                ret.setMsg("修改失败");
            }


        } catch (Exception e) {
            log.error(e.getMessage(), e);
            ret.setCode(ApiResponseEnum.API_RESPONSE_ERROR);
            ret.setMsg(e.getMessage());
        }

        return ret;
    }


    @RequestMapping(value = "/delRole", method = RequestMethod.POST)
    @ApiOperation(notes = "删除角色", httpMethod = "POST", value = "删除角色")
    public BaseRet<String> delRole(@ApiParam(value = "请求参数", required = true) @Valid @RequestBody ActionLibraryInfoParam param,
                                   BindingResult result) {

        BaseRet<String> ret = new BaseRet<String>();

        try {

            checkParam(result);

            if (iRoleService.delRole(param.getId())) {

                ret.setCode(ApiResponseEnum.API_RESPONSE_SUCCESS);
                ret.setMsg("删除成功");

            } else {

                ret.setCode(ApiResponseEnum.API_RESPONSE_ERROR);
                ret.setMsg("删除失败");
            }


        } catch (Exception e) {
            log.error(e.getMessage(), e);
            ret.setCode(ApiResponseEnum.API_RESPONSE_ERROR);
            ret.setMsg(e.getMessage());
        }

        return ret;
    }


    @RequestMapping(value = "/adminUserList", method = RequestMethod.POST)
    @ApiOperation(notes = "管理员列表", httpMethod = "POST", value = "管理员列表")
    public BaseRet<PageInfo<List<AdminUserListRet>>> adminUserList(@ApiParam(value = "请求参数", required = true) @Valid @RequestBody PageSearchParam param,
                                                                   BindingResult result) {

        BaseRet<PageInfo<List<AdminUserListRet>>> ret = new BaseRet<PageInfo<List<AdminUserListRet>>>();

        PageInfo<List<AdminUserListRet>> pageInfo = new PageInfo<List<AdminUserListRet>>();

        try {

            checkParam(result);

            int count = iRoleService.selectAdminListByCount(param.getSearchCondition());
            pageInfo.setCount(count);

            List<AdminUserListDto> list = iRoleService.selectAdminListByPage(param.getStart(), param.getPageSize(), param.getSearchCondition());

            List<AdminUserListRet> listRet = DozerMapperUtil.mapList(list, AdminUserListRet.class);

            pageInfo.setRecords(listRet);

            ret.setCode(ApiResponseEnum.API_RESPONSE_SUCCESS);
            ret.setMsg("查询成功");
            ret.setData(pageInfo);

        } catch (Exception e) {
            log.error(e.getMessage(), e);
            ret.setCode(ApiResponseEnum.API_RESPONSE_ERROR);
            ret.setMsg(e.getMessage());
        }

        return ret;
    }


    @RequestMapping(value = "/adminUserInfo", method = RequestMethod.POST)
    @ApiOperation(notes = "管理员详情", httpMethod = "POST", value = "管理员详情")
    public BaseRet<AdminUserInfoRet> adminUserInfo(@ApiParam(value = "请求参数", required = true) @Valid @RequestBody ActionLibraryInfoParam param,
                                                   BindingResult result) {

        BaseRet<AdminUserInfoRet> ret = new BaseRet<AdminUserInfoRet>();

        try {

            checkParam(result);

            LpAdminTbl info = iAdminService.selectUserInfoById(param.getId());

            AdminUserInfoRet adminUserInfoRet = new AdminUserInfoRet();
            adminUserInfoRet.setId(info.getId());
            adminUserInfoRet.setName(info.getName());
            adminUserInfoRet.setRoleId(info.getRoleId());
            if (StringUtils.isNotEmpty(info.getStoreId())) {
                adminUserInfoRet.setStoreId(JSONObject.parseArray(info.getStoreId(), Integer.class));
            }

            ret.setCode(ApiResponseEnum.API_RESPONSE_SUCCESS);
            ret.setMsg("查询成功");
            ret.setData(adminUserInfoRet);

        } catch (Exception e) {
            log.error(e.getMessage(), e);
            ret.setCode(ApiResponseEnum.API_RESPONSE_ERROR);
            ret.setMsg(e.getMessage());
        }

        return ret;
    }


    @RequestMapping(value = "/updateAdminUser", method = RequestMethod.POST)
    @ApiOperation(notes = "修改管理员信息", httpMethod = "POST", value = "修改管理员信息")
    public BaseRet<String> updateAdminUser(@ApiParam(value = "请求参数", required = true) @Valid @RequestBody UpdateAdminUserParam param,
                                           BindingResult result) {

        BaseRet<String> ret = new BaseRet<String>();

        try {

            checkParam(result);

            LpAdminTbl lpAdminTbl = new LpAdminTbl();
            lpAdminTbl.setId(param.getId());
            lpAdminTbl.setRoleId(param.getRoleId());
            lpAdminTbl.setName(param.getName());

            if (param.getStoreId().size() > 0) {
                JSONArray obj = JSONArray.fromObject(param.getStoreId());
                lpAdminTbl.setStoreId(obj.toString());
            }


            if (StringUtils.isNotEmpty(param.getPassword())) {
                lpAdminTbl.setPassword(CommonFunctionUtil.encryptionPwd(param.getPassword()));
            }

            if (iRoleService.updateAdmin(lpAdminTbl)) {

                ret.setCode(ApiResponseEnum.API_RESPONSE_SUCCESS);
                ret.setMsg("修改成功");

            } else {

                ret.setCode(ApiResponseEnum.API_RESPONSE_ERROR);
                ret.setMsg("修改失败");
            }


        } catch (Exception e) {
            log.error(e.getMessage(), e);
            ret.setCode(ApiResponseEnum.API_RESPONSE_ERROR);
            ret.setMsg(e.getMessage());
        }

        return ret;
    }


    @RequestMapping(value = "/addAdminUser", method = RequestMethod.POST)
    @ApiOperation(notes = "添加管理员信息", httpMethod = "POST", value = "添加管理员信息")
    public BaseRet<String> addAdminUser(@ApiParam(value = "请求参数", required = true) @Valid @RequestBody AddAdminUserParam param,
                                        BindingResult result) {

        BaseRet<String> ret = new BaseRet<String>();

        try {

            checkParam(result);

            List<LpAdminTbl> list = iAdminService.selectUserInfoByUsername(param.getUsername());

            if (list.size() <= 0) {

                LpAdminTbl lpAdminTbl = new LpAdminTbl();
                lpAdminTbl.setRoleId(param.getRoleId());
                lpAdminTbl.setName(param.getName());
                lpAdminTbl.setPassword(CommonFunctionUtil.encryptionPwd(param.getPassword()));
                if (param.getStoreId().size() > 0) {
                    JSONArray obj = JSONArray.fromObject(param.getStoreId());
                    lpAdminTbl.setStoreId(obj.toString());
                }
                lpAdminTbl.setUsername(param.getUsername());
                lpAdminTbl.setStatus(Constant.status.enable);

                if (iRoleService.addAdmin(lpAdminTbl)) {

                    ret.setCode(ApiResponseEnum.API_RESPONSE_SUCCESS);
                    ret.setMsg("添加成功");

                } else {

                    ret.setCode(ApiResponseEnum.API_RESPONSE_ERROR);
                    ret.setMsg("添加失败");
                }


            } else {

                ret.setCode(ApiResponseEnum.API_RESPONSE_ERROR);
                ret.setMsg("账号已存在");
            }


        } catch (Exception e) {
            log.error(e.getMessage(), e);
            ret.setCode(ApiResponseEnum.API_RESPONSE_ERROR);
            ret.setMsg(e.getMessage());
        }

        return ret;
    }


    @RequestMapping(value = "/updateAdminStatus", method = RequestMethod.POST)
    @ApiOperation(notes = "修改管理员账号状态", httpMethod = "POST", value = "修改管理员账号状态")
    public BaseRet<String> updateAdminStatus(@ApiParam(value = "请求参数", required = true) @Valid @RequestBody UpdateStatusParam param,
                                             BindingResult result) {

        BaseRet<String> ret = new BaseRet<String>();

        try {

            checkParam(result);

            LpAdminTbl lpAdminTbl = new LpAdminTbl();
            lpAdminTbl.setId(param.getId());
            lpAdminTbl.setStatus(param.getStatus());

            if (iRoleService.updateAdmin(lpAdminTbl)) {

                ret.setCode(ApiResponseEnum.API_RESPONSE_SUCCESS);
                ret.setMsg("修改成功");

            } else {

                ret.setCode(ApiResponseEnum.API_RESPONSE_ERROR);
                ret.setMsg("修改失败");
            }


        } catch (Exception e) {
            log.error(e.getMessage(), e);
            ret.setCode(ApiResponseEnum.API_RESPONSE_ERROR);
            ret.setMsg(e.getMessage());
        }

        return ret;
    }


    @RequestMapping(value = "/menuList", method = RequestMethod.POST)
    @ApiOperation(notes = "二级菜单列表", httpMethod = "POST", value = "二级菜单列表")
    public BaseRet<List<MenuListRet>> menuList() {

        BaseRet<List<MenuListRet>> ret = new BaseRet<List<MenuListRet>>();

        try {

            List<LpMenuTbl> list = iRoleService.selectMenuList();

            List<MenuListRet> listRet = DozerMapperUtil.mapList(list, MenuListRet.class);


            ret.setCode(ApiResponseEnum.API_RESPONSE_SUCCESS);
            ret.setMsg("查询成功");
            ret.setData(listRet);

        } catch (Exception e) {
            log.error(e.getMessage(), e);
            ret.setCode(ApiResponseEnum.API_RESPONSE_ERROR);
            ret.setMsg(e.getMessage());
        }

        return ret;
    }


    @RequestMapping(value = "/menuInfo", method = RequestMethod.POST)
    @ApiOperation(notes = "二级菜单详情", httpMethod = "POST", value = "二级菜单详情")
    public BaseRet<MenuInfoRet> menuInfo(@ApiParam(value = "请求参数", required = true) @Valid @RequestBody ActionLibraryInfoParam param,
                                         BindingResult result) {

        BaseRet<MenuInfoRet> ret = new BaseRet<MenuInfoRet>();

        try {

            LpMenuTbl info = iRoleService.selectMenuInfo(param.getId());

            MenuInfoRet menuInfoRet = new MenuInfoRet();
            menuInfoRet.setId(info.getId());
            menuInfoRet.setMenuUrl(info.getMenuUrl());
            menuInfoRet.setName(info.getName());
            menuInfoRet.setParentId(info.getParentId());

            ret.setCode(ApiResponseEnum.API_RESPONSE_SUCCESS);
            ret.setMsg("查询成功");
            ret.setData(menuInfoRet);

        } catch (Exception e) {
            log.error(e.getMessage(), e);
            ret.setCode(ApiResponseEnum.API_RESPONSE_ERROR);
            ret.setMsg(e.getMessage());
        }

        return ret;
    }


    @RequestMapping(value = "/updateMenu", method = RequestMethod.POST)
    @ApiOperation(notes = "修改二级菜单", httpMethod = "POST", value = "修改二级菜单")
    public BaseRet<String> updateMenu(@ApiParam(value = "请求参数", required = true) @Valid @RequestBody UpdateMenuParam param,
                                      BindingResult result) {

        BaseRet<String> ret = new BaseRet<String>();

        try {

            LpMenuTbl lpMenuTbl = new LpMenuTbl();
            lpMenuTbl.setId(param.getId());
            lpMenuTbl.setMenuUrl(param.getMenuUrl());
            lpMenuTbl.setName(param.getName());
            lpMenuTbl.setParentId(param.getParentId());
            lpMenuTbl.setUpdateTime(CommonFunctionUtil.getDateTime(Constant.formatType.second));

            if (iRoleService.updateMenu(lpMenuTbl)) {

                ret.setCode(ApiResponseEnum.API_RESPONSE_SUCCESS);
                ret.setMsg("修改成功");

            } else {

                ret.setCode(ApiResponseEnum.API_RESPONSE_ERROR);
                ret.setMsg("修改失败");
            }

        } catch (Exception e) {
            log.error(e.getMessage(), e);
            ret.setCode(ApiResponseEnum.API_RESPONSE_ERROR);
            ret.setMsg(e.getMessage());
        }

        return ret;
    }


    @RequestMapping(value = "/addMenu", method = RequestMethod.POST)
    @ApiOperation(notes = "添加二级菜单", httpMethod = "POST", value = "添加二级菜单")
    public BaseRet<String> addMenu(@ApiParam(value = "请求参数", required = true) @Valid @RequestBody AddMenuParam param,
                                   BindingResult result) {

        BaseRet<String> ret = new BaseRet<String>();

        try {

            LpMenuTbl lpMenuTbl = new LpMenuTbl();
            lpMenuTbl.setMenuUrl(param.getMenuUrl());
            lpMenuTbl.setName(param.getName());
            lpMenuTbl.setParentId(param.getParentId());
            lpMenuTbl.setUpdateTime(CommonFunctionUtil.getDateTime(Constant.formatType.second));
            lpMenuTbl.setInsertTime(CommonFunctionUtil.getDateTime(Constant.formatType.second));

            if (iRoleService.addMenu(lpMenuTbl)) {

                ret.setCode(ApiResponseEnum.API_RESPONSE_SUCCESS);
                ret.setMsg("添加成功");

            } else {

                ret.setCode(ApiResponseEnum.API_RESPONSE_ERROR);
                ret.setMsg("添加失败");
            }

        } catch (Exception e) {
            log.error(e.getMessage(), e);
            ret.setCode(ApiResponseEnum.API_RESPONSE_ERROR);
            ret.setMsg(e.getMessage());
        }

        return ret;
    }


    @RequestMapping(value = "/delMenu", method = RequestMethod.POST)
    @ApiOperation(notes = "删除二级菜单", httpMethod = "POST", value = "删除二级菜单")
    public BaseRet<String> delMenu(@ApiParam(value = "请求参数", required = true) @Valid @RequestBody ActionLibraryInfoParam param,
                                   BindingResult result) {

        BaseRet<String> ret = new BaseRet<String>();

        try {

            if (iRoleService.delMenu(param.getId())) {

                ret.setCode(ApiResponseEnum.API_RESPONSE_SUCCESS);
                ret.setMsg("删除成功");

            } else {

                ret.setCode(ApiResponseEnum.API_RESPONSE_ERROR);
                ret.setMsg("删除失败");
            }

        } catch (Exception e) {
            log.error(e.getMessage(), e);
            ret.setCode(ApiResponseEnum.API_RESPONSE_ERROR);
            ret.setMsg(e.getMessage());
        }

        return ret;
    }


    @RequestMapping(value = "/parentMenuList", method = RequestMethod.POST)
    @ApiOperation(notes = "一级菜单列表", httpMethod = "POST", value = "一级菜单列表")
    public BaseRet<List<ParentMenuListRet>> parentMenuList() {

        BaseRet<List<ParentMenuListRet>> ret = new BaseRet<List<ParentMenuListRet>>();

        try {

            List<LpParentMenuTbl> list = iRoleService.selectParentMenuList();

            List<ParentMenuListRet> listRet = DozerMapperUtil.mapList(list, ParentMenuListRet.class);

            ret.setCode(ApiResponseEnum.API_RESPONSE_SUCCESS);
            ret.setMsg("查询成功");
            ret.setData(listRet);

        } catch (Exception e) {
            log.error(e.getMessage(), e);
            ret.setCode(ApiResponseEnum.API_RESPONSE_ERROR);
            ret.setMsg(e.getMessage());
        }

        return ret;
    }


    @RequestMapping(value = "/parentMenuInfo", method = RequestMethod.POST)
    @ApiOperation(notes = "一级菜单详情", httpMethod = "POST", value = "一级菜单详情")
    public BaseRet<ParentMenuListRet> parentMenuInfo(@ApiParam(value = "请求参数", required = true) @Valid @RequestBody ActionLibraryInfoParam param,
                                                     BindingResult result) {

        BaseRet<ParentMenuListRet> ret = new BaseRet<ParentMenuListRet>();

        try {

            checkParam(result);

            LpParentMenuTbl info = iRoleService.selectParentMenuById(param.getId());

            ParentMenuListRet infoRet = DozerMapperUtil.map(info, ParentMenuListRet.class);

            ret.setCode(ApiResponseEnum.API_RESPONSE_SUCCESS);
            ret.setMsg("查询成功");
            ret.setData(infoRet);

        } catch (Exception e) {
            log.error(e.getMessage(), e);
            ret.setCode(ApiResponseEnum.API_RESPONSE_ERROR);
            ret.setMsg(e.getMessage());
        }

        return ret;
    }


    @RequestMapping(value = "/updateParentMenuInfo", method = RequestMethod.POST)
    @ApiOperation(notes = "修改一级菜单", httpMethod = "POST", value = "修改一级菜单")
    public BaseRet<String> updateParentMenuInfo(@ApiParam(value = "请求参数", required = true) @Valid @RequestBody UpdateParentMenuParam param,
                                                BindingResult result) {

        BaseRet<String> ret = new BaseRet<String>();

        try {

            checkParam(result);

            LpParentMenuTbl lpParentMenuTbl = new LpParentMenuTbl();
            lpParentMenuTbl.setId(param.getId());
            lpParentMenuTbl.setIcon(param.getIcon());
            lpParentMenuTbl.setName(param.getName());
            lpParentMenuTbl.setUpdateTime(CommonFunctionUtil.getDateTime(Constant.formatType.second));

            if (iRoleService.updateParentMenu(lpParentMenuTbl)) {
                ret.setCode(ApiResponseEnum.API_RESPONSE_SUCCESS);
                ret.setMsg("修改成功");
            } else {
                ret.setCode(ApiResponseEnum.API_RESPONSE_ERROR);
                ret.setMsg("修改失败");
            }


        } catch (Exception e) {
            log.error(e.getMessage(), e);
            ret.setCode(ApiResponseEnum.API_RESPONSE_ERROR);
            ret.setMsg(e.getMessage());
        }

        return ret;
    }


    @RequestMapping(value = "/addParentMenuInfo", method = RequestMethod.POST)
    @ApiOperation(notes = "添加一级菜单", httpMethod = "POST", value = "添加一级菜单")
    public BaseRet<String> addParentMenuInfo(@ApiParam(value = "请求参数", required = true) @Valid @RequestBody AddParentMenuParam param,
                                             BindingResult result) {

        BaseRet<String> ret = new BaseRet<String>();

        try {

            checkParam(result);

            LpParentMenuTbl lpParentMenuTbl = new LpParentMenuTbl();
            lpParentMenuTbl.setIcon(param.getIcon());
            lpParentMenuTbl.setUpdateTime(CommonFunctionUtil.getDateTime(Constant.formatType.second));
            lpParentMenuTbl.setName(param.getName());
            lpParentMenuTbl.setInsertTime(CommonFunctionUtil.getDateTime(Constant.formatType.second));

            if (iRoleService.insertParentMenu(lpParentMenuTbl)) {
                ret.setCode(ApiResponseEnum.API_RESPONSE_SUCCESS);
                ret.setMsg("添加成功");
            } else {
                ret.setCode(ApiResponseEnum.API_RESPONSE_ERROR);
                ret.setMsg("添加失败");
            }


        } catch (Exception e) {
            log.error(e.getMessage(), e);
            ret.setCode(ApiResponseEnum.API_RESPONSE_ERROR);
            ret.setMsg(e.getMessage());
        }

        return ret;
    }


    @RequestMapping(value = "/delParentMenu", method = RequestMethod.POST)
    @ApiOperation(notes = "删除一级菜单", httpMethod = "POST", value = "删除一级菜单")
    public BaseRet<String> delParentMenu(@ApiParam(value = "请求参数", required = true) @Valid @RequestBody ActionLibraryInfoParam param,
                                         BindingResult result) {

        BaseRet<String> ret = new BaseRet<String>();

        try {

            if (iRoleService.delParentMenuById(param.getId())) {

                ret.setCode(ApiResponseEnum.API_RESPONSE_SUCCESS);
                ret.setMsg("删除成功");

            } else {

                ret.setCode(ApiResponseEnum.API_RESPONSE_ERROR);
                ret.setMsg("删除失败");
            }

        } catch (Exception e) {
            log.error(e.getMessage(), e);
            ret.setCode(ApiResponseEnum.API_RESPONSE_ERROR);
            ret.setMsg(e.getMessage());
        }

        return ret;
    }
}
